package org.ucas.faker.web.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.ucas.faker.web.dao.ApplicationDao;
import org.ucas.faker.web.entity.Application;

import javax.transaction.Transactional;
import java.util.List;

/**
 * Created by suemi on 17-7-7.
 */
@Transactional
@Service
public class ApplicationService {

  @Autowired
  private ApplicationDao applicationDao;

  public List<Application> persist(Iterable<Application> applications) {
    return applicationDao.save(applications);
  }

  public void clear() {
    applicationDao.clear();;
  }

  public Application load(String code) {
    return applicationDao.findOne(code);
  }

  public List<Application> list(String category) {
    return category == null ? applicationDao.findAll() : applicationDao.listByCategory(category);
  }
}
